package com.kmproject.haifu.mvp.ui.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.blankj.utilcode.util.StringUtils;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.ExtensionUtilKt;
import com.kmproject.haifu.mvp.model.entity.beans.HomeBannerBean;
import com.kmproject.haifu.mvp.ui.widget.RoundCornerImageView;
import com.zhouwei.mzbanner.holder.MZViewHolder;

public class HomeBannerViewHolder implements MZViewHolder<HomeBannerBean> {
    private RoundCornerImageView mImageView;
    private ImageLoader glideImage;
    private Context mContext;

    @Override
    public View createView(Context context) {
        mContext = context;
        // 返回页面布局
        View view = LayoutInflater.from(context).inflate(R.layout.item_home_banner, null);
        mImageView = view.findViewById(R.id.imv_img);
        return view;
    }

    @Override
    public void onBind(Context context, int i, HomeBannerBean homeBannerBean) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        if (homeBannerBean != null && !StringUtils.isTrimEmpty(homeBannerBean.getImageUrl())) {
            ExtensionUtilKt.loadImage(mImageView, homeBannerBean.getImageUrl());
            glideImage.loadImage(mContext, ImageConfigImpl.builder().url(homeBannerBean.getImageUrl())
                    .imageView(mImageView.setmBorderRadius(10))
                    .build());
        }
    }
}
